<?php

/*	Vulpes-backend - Web-based managegent for wireless internet providers.
	Copyright (C) 2007 LinFox Serviços em Informática Ltda.

	This file is part of the Vulpes backend.

	Vulpes-backend is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Vulpes-backend is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

 	Please note that any front-end (client application) that is distributed
	along with the Vulpes back-end, such as the Vulpes front-end by LinFox,
	is subject to it's correspending licene. */

require_once 'model.php';

class client extends model
{
	private $verified = false;
	private $auth = false;

	public function __construct()
	{
		$this->password = '';
	}

	function verify()
	{
		if ($_POST['action'] == 'logout' || $_GET['action'] == 'logout') {
			$_SESSION = array();
			session_destroy();
			return false;
		} elseif (isset($_POST['client_username']) && isset($_POST['client_password']) && $_SESSION['vulpes_client_session'] != true) {

			if ($this->password == hash('sha512', $_POST['client_password'])) {
				$_SESSION['vulpes_client_session'] = true;
				$_SESSION['vulpes_client_username'] = $this->username;
				$_SESSION['vulpes_client_name'] = $this->name;
				$_SESSION['vulpes_client_email'] = $this->email;
			} else {
				return false;
			}
		}
		
		if ($_SESSION['vulpes_client_session'] == true) return true;
		return false;
	}
	
	function info()
	{
		if (!$this->exists) {
			$this->error = 'client_doesnt_exist';
			return false;
		}
		$result = '<client>' . $this->xml_iterate();
		foreach ($this->contracts as &$contract) {
			$result .= $contract->xml_iterate();
		}
		$result .= '</client>';
		return $result;
	}
	
	function set_password($password)
	{
		$this->password = hash('sha512', $password); 
	}

}

?>
